package com.wondedDream.controller.web;

import com.wondedDream.model.Practice;
import com.wondedDream.model.User;
import com.wondedDream.service.PracticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController(value = "webPracticeController")
@RequestMapping("/web/practice")
@Api(description = "客户端-用户练习模块")
public class UserPracticeController {

    @Autowired
    private PracticeService practiceService;


    // 获取课程信息
    @GetMapping("/{id}")
    @ApiOperation(value = "获取练习信息")
    public Practice getPracticeById(@PathVariable Integer id) {
        return practiceService.getPracticeById(id);
    }

    // 获取某一分类下的课程列表
    @GetMapping("/byCategoryAndOpenId")
    @ApiOperation(value = "获取用户某一分类下的练习列表")
    public List<Practice> getPracticesByCategoryIdAndOpenId(@RequestParam("categoryId") Integer categoryId,
                                                            @RequestParam("userOpenId") String userOpenId) {
        return practiceService.getPracticesByCategoryIdAndOpenId(categoryId,userOpenId);
    }

    // 获取所有课程列表
    @GetMapping("/")
    @ApiOperation(value = "获取所有练习列表")
    public List<Practice> getAllPractices() {
        return practiceService.getAllPractices();
    }

    // 创建新的模考问题
    @PostMapping("/createPracticeQuestionByFileJson")
    @ApiOperation(value = "根据文件导入模考题库")
    public String createPracticeQuestionByFileJson() {
        practiceService.createPracticeQuestionByFileJson();
        return "success";
    }
}